Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests for GitDsc #87

Closed
wants to merge 12 commits into from
Closed

Add some tests for GitDsc #87

wants to merge 12 commits into from

Conversation

Trenly
Copy link
Contributor

@Trenly Trenly commented Nov 1, 2024

I noticed that the GitConfigFile resource in the GitDsc module didn't actually exist. So, I removed it and added the test for listing the available resources. I also added a basic test for the GitClone resource. I wasn't familiar enough with the other resources in the module to add tests for them, but I figured that some tests were better than none. If this PR merges, I'll raise an issue for tracking that the additional tests should be added


@ryfu-msft
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Trenly
Copy link
Contributor Author

Trenly commented Nov 1, 2024

o.O They ran locally for me. . . Time to debug!

@ryfu-msft
Copy link
Contributor

o.O They ran locally for me. . . Time to debug!

You might need to rearrange the order so that the helper functions are first before the Assert-Git

@Trenly
Copy link
Contributor Author

Trenly commented Nov 1, 2024

I think the issue is actually that Git just isn't installed, so there is no way for it to actually clone the repository.
I think this leaves 2 options -

  1. Have the tests install Git using Microsoft.WinGet.DSC
  2. Have some test data or test files that can be copied to the directory in place of asserting that the actual process of running git clone works

Edit: Just realized that option 2 won't work, since that also requires git to be installed 🤦

@Trenly
Copy link
Contributor Author

Trenly commented Nov 2, 2024

Okay, that was harder than I thought it would be, since Pester doesn't like to play nice if you don't have the scopes set juuuuuust right, but I think I got it to work

@ryfu-msft
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@ryfu-msft ryfu-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one fix and the rest looks good

resources/GitDsc/GitDsc.psd1 Outdated Show resolved Hide resolved
@ryfu-msft
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Trenly
Copy link
Contributor Author

Trenly commented Nov 4, 2024

Okay, now I'm truly lost. This is the error on line 22 -

##[error] [-] Discovery in D:\a\_work\1\s\tests\GitDsc\GitDsc.Tests.ps1 failed with:
##[error] System.Management.Automation.ActionPreferenceStopException: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The 'Assert-Git' command was found in the module 'GitDsc', but the module could not be loaded. For more information, run 'Import-Module GitDsc'.

But yet the module is imported on line 19 in the BeforeAll block ???

Edit: When the module is imported, it calls Assert-Git. That assertion fails because Git is not installed in the pipelines. The failed assertion throws, which causes Pester to not be able to bind into the container

@Trenly Trenly requested a review from ryfu-msft November 5, 2024 21:05
@ryfu-msft
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ryfu-msft
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Trenly
Copy link
Contributor Author

Trenly commented Nov 5, 2024

Why do I even try. I uninstalled Git, and the tests passed for me. I tried it in a VM, and the tests passed for me. I have no clue what's going wrong. I'll revisit this later once I have a bit more time

@Trenly Trenly closed this Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants